package com.qianda.qdminiapp.security;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.qianda.qdminiapp.controller.Result;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName LogoutSuccessResultHandler
 * @Author cw
 * @Date 2019/7/1 11:53
 **/
public class LogoutSuccessResultHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest req,
                                HttpServletResponse resp,
                                Authentication auth) throws IOException, ServletException {

        resp.setCharacterEncoding("utf-8");
        resp.setContentType("application/json");

        resp.getWriter().write(JSON.toJSONString(
                Result.success(), SerializerFeature.WriteMapNullValue));

    }
}
